package com.example.yiwei.crm.json;


import com.example.yiwei.crm.entity.UserCarCustomerEntity;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2018/1/24.
 */

public class UseCarCustomerJson {
    public static List<UserCarCustomerEntity> get(String result){
        List<UserCarCustomerEntity> list ;
        UserCarCustomerEntity entity;
        try {
            JSONObject object = new JSONObject(result);
            JSONArray array=object.getJSONArray("list");
            list = new ArrayList<>();
            for (int i=0;i<array.length();i++){
                entity = new UserCarCustomerEntity();
                JSONObject json=array.getJSONObject(i);
                if (json.has("KAA02")){
                    entity.setName(json.getString("KAA02"));
                }
                if (json.has("KYA01")){
                    entity.setId(json.getString("KYA01"));
                }
                if (json.has("KAADZ")){
                    entity.setAddress(json.getString("KAADZ"));
                }
                if (json.has("KYA02")){
                    entity.setTime(json.getString("KYA02"));
                }

                list.add(entity);
            }
            return list;
        } catch (JSONException e) {
            e.printStackTrace();
        }

        return null;

    }
}
